﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CP.Entities;
using CP.Win.IViews.GPM;
using CP.Repositories.GPM;
using CP.Utility;
using System.Data;

namespace CP.Controllers.GPM
{
    public class ListAuthorizeController
    {
        public IListAuthorizeView View { get; private set; }
        public ListAuthorizeRepsitory Repository { get; private set; }

        public ListAuthorizeController(IListAuthorizeView view)
        {
            this.View = view;
            this.Repository = new ListAuthorizeRepsitory();

            this.View.AuthList += new AuthListHandler(View_AuthList);
            this.View.UnAuthList += new UnAuthListHandler(View_UnAuthList);
            this.View.EditValueChanged += new EditValueChangedHandler(View_EditValueChanged);  
        }

        void View_EditValueChanged(int groupid, int menuid)
        {
            IList<Column_List> unAuthBtns = this.Repository.GetUnAuthCols(groupid, menuid);
            this.View.BindUnAuthCols(unAuthBtns);
            IList<Column_List> authBtns = this.Repository.GetAuthCols(groupid, menuid);
            this.View.BindAuthCols(authBtns);
        }

        void View_AuthList(int groupid, int menuid, IList<int> btns)
        {
            this.Repository.ListAuth(groupid, menuid, btns);
        }

        void View_UnAuthList(int groupid, int menuid, IList<int> btns)
        {
            this.Repository.ListUnAuth(groupid, menuid, btns);
        }

    }
}
